#ifndef _WAVEFORM_H_
#define _WAVEFORM_H_

#include <vector>
#include <cmath>

class Waveform {
  std::vector <float> _signal;
  int _sampleRate;
  int _duration;
  
 public:
  
  Waveform( int duration, int sampleRate ) {
    _sampleRate = sampleRate; _duration = duration;
    // initialize our waveform to 0
    _signal.resize( _sampleRate * _duration, 0 );
  }
  
  float& operator[](int idx) {
    return _signal[idx];
  }

  void reset(void) {
    _signal.clear();
    _signal.resize( _sampleRate * _duration );
  }

  int size(void) const { 
    return _signal.size();
  }

  int getSampleRate(void) const {
    return _sampleRate;
  }

  int getDuration(void) const {
    return _duration;
  }
  
  std::vector<float> getAsVector(void) const { 
    return _signal;
  }


  void insertSine(int left, int right, float freq) {
    if(left < 0 || right > _signal.size()-1) { 
      printf("Selection out of bounds. Not inserting.\n");
      return; 
    }
    
    float PI = 3.1415926535897932384;
    
    for(int i = left; i <= right; i+=1) {
      _signal[i] = sin( 2*PI * freq * i/_sampleRate);
    }

  }

  void insertTriangle(int left, int right, float freq) {
    if(left < 0 || right > _signal.size()-1) { 
      printf("Selection out of bounds. Not inserting.\n");
      return; 
    }
    
    float amp = 1.0;
    float PI = 3.1415926535897932384;
    
    for(int i = left+1; i <= right; i+=1)  {
      _signal[i] = freq * i / _sampleRate
    }
  
  }

};


#endif
